'Menu=SubMenu;ALIENS;SubMenu;SubMenu
'Menu=Divider;Divider;Divider;Divider
'Menu=QAALIENS.brn;QAALIENS.brn  Question & Answer Brain;This is a huge database of keyword lists and sentences associated with those lists. Hal will compare the users sentence with each keyword list in this file and will choose the most relevant one. If more than one response with the same relevance exists, then one will be randomly chosen.;QABrain
'Menu=KEYWORDALIENS.brn;KEYWORDALIENS.brn Word List; a list of keywords To trigger learning from users;TopicSearchTRUE
'Menu=statementALIENS.BRN;statementALIENS.BRN Sentences;A SET OF STATEMENTS learned from users;SentenceList


'--------------------------------------------------------------------------------------------------
' ALIENS TOPIC SCRIPT
' this script contains a menu, QABRAIN, STATMENT & KEY WORD BRAIN. 
'--------------------------------------------------------------------------------------------------

'OBTAIN RESPONSE from Q&A BRAIN and process for relevence

If ((Len(GetResponse) < 4 Or UserBrainRel < 10 And GetResponseBlock <> True) Or DebugMode = True) Then

 'GET THE RESPONSE
    QAALIENS_response = HalBrain.QABrain(UCase(UserSentence), WorkingDir & "QAALIENS.brn", UserBrainRel)
    QAALIENS_response2 = HalBrain.FragmentMatch(UserSentence, WorkingDir & "QAALIENS.brn")

 'PUT THE RESPONSE IN TO haluserbrain variable for procssing.
    HalUserBrain = QAALIENS_response

 'CHECK REPETITION
        CheckRepetition = False
		If HalBrain.CheckRepetition(QAALIENS_response, PrevSent) = True Then CheckRepetition = True 
		If HalBrain.CheckRepetition(QAALIENS_response, PrevUserSent) = True Then CheckRepetition = True 
        End If 
        
        
'PROCESS Relevency
    If UserBrainRel > HighestRel Then
			HighestRel = UserBrainRel
			HighestRelResponse = HalUserBrain
	End If

'This formula lets the user define the hurdle in Hal's options
    Score = UserBrainRel + 1
    Hurdle = GainControl + 20 - Int(((Learninglevel - 15) * 0.8)) 
    'formula RESULTS TO DEBUG
    DebugInfo = DebugInfo & "QAALIENS.brn has returned """ & HalUserBrain & """ which had a relevance of " & Score & " which was compared to " & Hurdle & ". "
 

'OUTPUT A RESPONSE
		If Len(GetResponse) < 4 And Score > Hurdle And CheckRepetition = False Then
			GetResponse = " " & HalUserBrain & VbCrLf
    'dEBUG info
			DebugInfo = DebugInfo & "Hal has decided to use this sentence." & HalUserBrain & VbCrLf
		Else
		    DebugInfo = DebugInfo & "Hal has decided not to use this sentence." & HalUserBrain & VbCrLf
        End If




	
'RESPOND LEARNED STATEMENTS
If HalBrain.TopicSearch(OriginalSentence, WorkingDir & "KEYWORDALIENS.brn") = "TRUE" Then
    'GET THE RESPONSE(STATEMENTS)
     QAstatementALIENS = HalBrain.ChooseSentenceFromFile(WorkingDir & "statementALIENS.BRN")
     GetResponse = " " & QAALIENS_response2 & QAstatementALIENS & VbCrLf
    'DEBUG INFO
     DebugInfo = DebugInfo & "hal  HAS RESPONDED WITH a prevstatement from statementsALIENS.BRN " & GetResponse & VbCrLf
Else
	 DebugInfo = DebugInfo & "hal HAS not RESPONDED WITH a prevstatement from statementALIENS.BRN" & GetResponse & VbCrLf
End If

'SAVE FILES:
    'check personal keyword file
If HalBrain.TopicSearch(OriginalSentence, WorkingDir & "KEYWORDALIENS.brn") = "TRUE" And GetResponseBlock <> True And CheckRepetition = False Then

    'SAVE q&a paired response
        HalBrain.AppendFile WorkingDir & "QAALIENS.brn", "@" & UserSentence & VbCrLf & " " & UCase(PrevSent)

    'SAVE STATMENT : for later use
        AnswerSent = "" & Trim(UserSentence)
        HalBrain.AppendFile WorkingDir & "statementALIENS.BRN" & ".brn", AnswerSent

    'debuG info
        DebugInfo = DebugInfo & "Hal has THOUGHT ABOUT IT AND SAVED" & AnswerSent 
Else
	DebugInfo = DebugInfo & "Hal has decided not to SAVE this ." & AnswerSent & VbCrLf
End If
 








